package com.kangfawei.thread;

public class JoinTest{
    public static void main(String[] args) {
        Thread thread = new Thread(new Father());
        thread.start();
    }

}

class Father implements Runnable{

    @Override
    public void run() {
        System.out.println("爸爸在抽烟......");
        for (int i = 0; i < 30; i++) {
            try {
                System.out.println("爸爸在抽第"+(i+1)+"根烟......");
                Thread.sleep(500);
                System.out.println("爸爸抽完了第"+(i+1)+"根烟......");
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(i == 19){
                System.out.println("爸爸发现烟没有了，让儿子去买烟......");
                Thread thread = new Thread(new Son());
                try {
                    thread.start();
                    thread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

class Son implements Runnable{
    @Override
    public void run() {
        System.out.println("儿子接过零钱区买烟....");
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(i+1+"分钟过去了......");
        }
        System.out.println("儿子买烟回来了");
    }
}